diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-09-07 22:31:23 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-09-07 22:31:23 +0200 |
| commit | 992e40835af1600a0961ec2454fb78ff43aec3c6 (patch) | |
| tree | 3c0602ae64a186ce5ac51be6b0795037488f552a /src/routes/projects/[projectId]/routine/[routineId]/+page.server.ts | |
| parent | e4a158965f3fcfe6fac65a1eba7b456d615e7dca (diff) | |
Add routine archives: archive date, searchable archived list, frozen page
- Stamp archived_at on the archived snapshot; copy it on edit
- loadArchived(projectId) + collapsible fuzzy-searched "Archivées" section on the project page
- Archived routine pages open read-only with the health chart ending at the archive date; edit/complete actions reject archived routines
Diffstat (limited to 'src/routes/projects/[projectId]/routine/[routineId]/+page.server.ts')
| -rw-r--r-- | src/routes/projects/[projectId]/routine/[routineId]/+page.server.ts | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/routes/projects/[projectId]/routine/[routineId]/+page.server.ts b/src/routes/projects/[projectId]/routine/[routineId]/+page.server.ts index 83bac3c..f2b6551 100644 --- a/src/routes/projects/[projectId]/routine/[routineId]/+page.server.ts +++ b/src/routes/projects/[projectId]/routine/[routineId]/+page.server.ts @@ -31,21 +31,31 @@ export const load: PageServerLoad = async ({ params }) => { } const routine = await loadCurrent(routineId); - if (!routine || routine.archived || routine.projectId !== projectId) { + if (!routine || routine.projectId !== projectId) { throw error(404, 'Routine introuvable'); } const completions = await loadCompletions(routineId); + // An archived routine is frozen at its archive instant: state and chart + // stop there instead of now. + const at = routine.archivedAt ? Date.parse(routine.archivedAt) : Date.now(); return { project: { id: project.id, name: project.name }, routine, completions, - state: computeRoutineState(routine, completions, Date.now()), + state: computeRoutineState(routine, completions, at), }; }; export const actions: Actions = { edit: async ({ request, params }) => { + const current = await loadCurrent(numericId(params.routineId)); + if (!current) { + return fail(400, { error: 'Routine introuvable' }); + } + if (current.archived) { + return fail(400, { error: 'Routine archivée' }); + } const data = await request.formData(); const name = parseFormString(data.get('name')); if (!name) { @@ -65,6 +75,13 @@ export const actions: Actions = { }, complete: async ({ request, params }) => { + const current = await loadCurrent(numericId(params.routineId)); + if (!current) { + return fail(400, { error: 'Routine introuvable' }); + } + if (current.archived) { + return fail(400, { error: 'Routine archivée' }); + } const data = await request.formData(); try { await complete( |
